//
//  Point_Other_example.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/14.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef Point_Other_example_hpp
#define Point_Other_example_hpp

#include <stdio.h>
#include <string>
#include <iostream>

class Animal
{
protected:
    std::string m_name;
    
    // We're making this constructor protected because
    // we don't want people creating Animal objects directly,
    // but we still want derived classes to be able to use it.
    Animal(std::string name)
    : m_name(name)
    {
    }
    
public:
    std::string getName() { return m_name; }
    const char* speak() { return "???"; }
};

class Cat: public Animal
{
public:
    Cat(std::string name)
    : Animal(name)
    {
    }
    
    const char* speak() { return "Meow"; }
};

class Dog: public Animal
{
public:
    Dog(std::string name)
    : Animal(name)
    {
    }
    
    const char* speak() { return "Woof"; }
};

/*
 Cat cat("Fred");
 std::cout << "cat is named " << cat.getName() << ", and it says " << cat.speak() << '\n';
 
 Dog dog("Garbo");
 std::cout << "dog is named " << dog.getName() << ", and it says " << dog.speak() << '\n';
 
 Animal *pAnimal = &cat;
 std::cout << "pAnimal is named " << pAnimal->getName() << ", and it says " << pAnimal->speak() << '\n';
 
 pAnimal = &dog;
 std::cout << "pAnimal is named " << pAnimal->getName() << ", and it says " << pAnimal->speak() << '\n';
 
 
 结果:
 
 cat is named Fred, and it says Meow
 dog is named Garbo, and it says Woof
 pAnimal is named Fred, and it says ???
 pAnimal is named Garbo, and it says ???
 
 */

#endif /* Point_Other_example_hpp */
